//
//  BuaatVolunteerServerSDK.m
//  BuaatVolunteerServerSDK
//
//  Created by mac on 15/6/26.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "BuaatVolunteerServerSDK.h"
#import "AFNetworking.h"
#import "BuaatRSA.h"
#define BuaatVolunteerServerSDKLocalHost @"http://192.168.1.11:8080"
//#define BuaatVolunteerServerSDKLocalHost  @"http://58.252.106.168:18080/"
//#define BuaatVolunteerServerSDKLocalHost @"https://open.qnzyz.org.cn"

#define apiUrl [BuaatVolunteerServerSDKLocalHost stringByAppendingPathComponent:@"api/v1"]

static BuaatVolunteerServerSDK *singleton=nil;
@interface BuaatVolunteerServerSDK()
@property(strong,nonatomic)BuaatRSA *rsa;
@property(strong,nonatomic)AFHTTPRequestOperationManager *manager;

@property(strong,nonatomic)NSString *clientId;
@property(strong,nonatomic)NSString *appKey;

@property(strong,nonatomic)NSString *token;
@property(strong,nonatomic)NSDate *tokenTimeOut;
@end

@implementation BuaatVolunteerServerSDK
#pragma mark - alloc
+ (id) allocWithZone:(NSZone *)zone //第三步：重写allocWithZone方法
{
    @synchronized (self) {
        if (singleton == nil) {
            singleton = [super allocWithZone:zone];
            return singleton;
        }
    }
    return nil;
}

- (id) copyWithZone:(NSZone *)zone //第四步
{
    return self;
}


#pragma mark - done

+ (BuaatVolunteerServerSDK*) sharedInstance
{
    @synchronized (self)
    {
        if(singleton==nil){
            singleton=[[BuaatVolunteerServerSDK alloc]init];
        }
    }
    return singleton;
}

-(instancetype)init{
    if(self=[super init]){
        self.manager=[AFHTTPRequestOperationManager manager];
        self.manager.requestSerializer=[AFJSONRequestSerializer serializer];
        
    }
    return self;
}

-(void)setClientId:(NSString *)clientId appKey:(NSString *)appKey{
    self.clientId=clientId;
    self.appKey=appKey;
    
    if(self.appKey.length==64+64+64+24){
        self.rsa=[[BuaatRSA alloc]init];
        
        [self.rsa setPublicKey:appKey];
    }else{
        self.rsa=nil;
    }
    
    

    
    
    
    NSString *userDefaultsClientId=[[NSUserDefaults standardUserDefaults]valueForKey:@"BuaatVolunteerServerSDKClientId"];
    if([self.clientId isEqualToString:userDefaultsClientId]){
        self.token=[[NSUserDefaults standardUserDefaults]valueForKey:@"BuaatVolunteerServerSDKToken"];
        NSDateFormatter *f=[[NSDateFormatter alloc]init];
        [f setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        self.tokenTimeOut=[f dateFromString:[[NSUserDefaults standardUserDefaults]valueForKey:@"BuaatVolunteerServerSDKTokenTimeOutStr"]];
    }else{
        [[NSUserDefaults standardUserDefaults]setObject:self.clientId forKey:@"BuaatVolunteerServerSDKClientId"];
        [[NSUserDefaults standardUserDefaults]setObject:@"" forKey:@"BuaatVolunteerServerSDKToken"];
        [[NSUserDefaults standardUserDefaults]setObject:@"" forKey:@"BuaatVolunteerServerSDKTokenTimeOutStr"];
        [[NSUserDefaults standardUserDefaults]synchronize];
    }
    
    
}

#pragma mark - 请求服务接入令牌
-(void)requestTokenWithSuccess:(void (^)(int ret,NSString *token,NSString *expireTime))success
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId!=nil&&self.appKey!=nil){
        if([[NSDate date]compare:self.tokenTimeOut]==NSOrderedDescending||self.tokenTimeOut==nil||self.token.length==0){
        
        }else{
            if(success){
                success(0,self.token,[[NSUserDefaults standardUserDefaults]valueForKey:@"BuaatVolunteerServerSDKTokenTimeOutStr"]);
            }
            return;
        }
        NSDateFormatter *f=[[NSDateFormatter alloc]init];
        [f setDateFormat:@"yyyyMMddHHmmss"];
        NSString *dateStr=[f stringFromDate:[NSDate date]];
        NSString *infoStr=[NSString stringWithFormat:@"%@|%@",self.clientId,dateStr];
        
        NSString *info=[self.rsa encryptStrWithPublicKey:infoStr];
        info = (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(__bridge CFStringRef)info,NULL,CFSTR("!*'();:@&=+$,/?%#[]"),kCFStringEncodingUTF8);
        
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/token?client_id=%@&info=%@",BuaatVolunteerServerSDKLocalHost,self.clientId,info];
        
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([responseObject isKindOfClass:[NSDictionary class]]){
                if(responseObject[@"result"][@"token"]!=nil&&![responseObject[@"result"][@"token"] isKindOfClass:[NSNull class]]){
                    NSString *netToken=responseObject[@"result"][@"token"];
                    self.token=[self.rsa decryptStrWithPublicKey:netToken];
                    NSString *timeOutStr=responseObject[@"result"][@"expireTime"];
                    NSDateFormatter *f=[[NSDateFormatter alloc]init];
                    [f setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
                    self.tokenTimeOut=[f dateFromString:timeOutStr];
                    if(success){
                        success([responseObject[@"ret"] intValue],self.token,timeOutStr);
                    }
                    [[NSUserDefaults standardUserDefaults]setObject:self.token forKey:@"BuaatVolunteerServerSDKToken"];
                    [[NSUserDefaults standardUserDefaults]setObject:timeOutStr forKey:@"BuaatVolunteerServerSDKTokenTimeOutStr"];
                    [[NSUserDefaults standardUserDefaults]synchronize];
                }
            }
            
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.response,error);
            }
        }];
    
    }else{
        NSError *error=[[NSError alloc]initWithDomain:@"请注册有效的clientId和appKey" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
    }
}

#pragma mark - 志愿者团体注册
-(void)requestGroupRegisterWithOrgCode:(NSString *)orgCode
                           groupName:(NSString *)groupName
                           groupType:(NSString *)groupType
                        groupAdmCode:(NSString *)groupAdmCode
                        groupAddress:(NSString *)groupAddress
                       groupPostcode:(NSString *) groupPostcode
                      groupAdmMobile:(NSString *)groupAdmMobile
                         groupAdmPwd:(NSString *)groupAdmPwdAfterMD5
                        groupAdmName:(NSString *)groupAdmName
                        groupAdmIdNo:(NSString *)groupAdmIdNo
                         groupAdmTel:(NSString *)groupAdmTel
                             success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                             failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(token.length!=0){
            if(orgCode.length==0||groupType.length==0||groupAddress.length==0||groupPostcode.length==0||groupAdmMobile.length==0||groupAdmPwdAfterMD5.length==0||groupAdmName.length==0||groupAdmIdNo.length==0||groupAdmTel.length==0){
                NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
                if(failure){
                    failure(nil,error);
                }
                return;
            }
            if([groupType intValue]==2){
                if(groupAdmCode.length==0){
                    NSError *error=[[NSError alloc]initWithDomain:@"志愿者团体机构代码不能为空" code:0 userInfo:nil];
                    if(failure){
                        failure(nil,error);
                    }
                    return;
                }
            }
            NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
            if(groupAdmCode.length==0){
                [parameters setValuesForKeysWithDictionary:@{@"groupAdmCode":[NSNull null]}];
            }else{
                [parameters setValuesForKeysWithDictionary:@{@"groupAdmCode":groupAdmCode}];
            }
            [parameters setValuesForKeysWithDictionary:@{@"orgCode":orgCode,@"groupName":groupName,@"groupType":groupType,@"groupAddress":groupAddress,@"groupPostcode":groupPostcode,@"groupAdmMobile":groupAdmMobile,@"groupAdmPwd":groupAdmPwdAfterMD5,@"groupAdmName":groupAdmName,@"groupAdmIdNo":groupAdmIdNo,@"groupAdmTel":groupAdmTel}];
            NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/group/reg?client=%@&token=%@",apiUrl,self.clientId,token];
            [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
                if([self isRefreshWithResponseObject:responseObject]){
                    [self requestGroupRegisterWithOrgCode:orgCode groupName:groupName groupType:groupType groupAdmCode:groupAdmCode groupAddress:groupAddress groupPostcode:groupPostcode groupAdmMobile:groupAdmMobile groupAdmPwd:groupAdmPwdAfterMD5 groupAdmName:groupAdmName groupAdmIdNo:groupAdmIdNo groupAdmTel:groupAdmTel success:success failure:failure];
                }else{
                    if(success){
                        success(operation.responseObject,responseObject);
                    }
                }
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                if(failure){
                    failure(operation.responseObject,error);
                }
            }];

        }
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 志愿者团体信息更新
-(void)requestGroupUpdateWithGroupCode:(NSString *)groupCode
                         groupName:(NSString *)groupName
                         groupType:(NSString *)groupType
                      groupAdmCode:(NSString *)groupAdmCode
                      groupAddress:(NSString *)groupAddress
                     groupPostcode:(NSString *)groupPostcode
                    groupAdmMobile:(NSString *)groupAdmMobile
                      groupAdmName:(NSString *)groupAdmName
                      groupAdmIdNo:(NSString *)groupAdmIdNo
                       groupAdmTel:(NSString *)groupAdmTel
                           success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                           failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(self.token!=0){
            if(groupCode.length==0||groupType.length==0||groupAddress.length==0||groupPostcode.length==0||groupAdmMobile.length==0||groupAdmName.length==0||groupAdmIdNo.length==0||groupAdmTel.length==0){
                NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
                if(failure){
                    failure(nil,error);
                }
                return;
            }
            if([groupType intValue]==2){
                if(groupAdmCode.length==0){
                    NSError *error=[[NSError alloc]initWithDomain:@"志愿者团体机构代码不能为空" code:0 userInfo:nil];
                    if(failure){
                        failure(nil,error);
                    }
                    return;
                }
            }
            NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
            if(groupAdmCode.length==0){
                [parameters setValuesForKeysWithDictionary:@{@"groupAdmCode":[NSNull null]}];
            }else{
                [parameters setValuesForKeysWithDictionary:@{@"groupAdmCode":groupAdmCode}];
            }
            [parameters setValuesForKeysWithDictionary:@{@"groupCode":groupCode,@"groupName":groupName,@"groupType":groupType,@"groupAddress":groupAddress,@"groupPostcode":groupPostcode,@"groupAdmMobile":groupAdmMobile,@"groupAdmName":groupAdmName,@"groupAdmIdNo":groupAdmIdNo,@"groupAdmTel":groupAdmTel}];
            NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/group/update?client=%@&token=%@",apiUrl,self.clientId,token];
            [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
                if([self isRefreshWithResponseObject:responseObject]){
                    [self requestGroupUpdateWithGroupCode:groupCode groupName:groupName groupType:groupType groupAdmCode:groupAdmCode groupAddress:groupAddress groupPostcode:groupPostcode groupAdmMobile:groupAdmMobile groupAdmName:groupAdmName groupAdmIdNo:groupAdmIdNo groupAdmTel:groupAdmTel success:success failure:failure];
                }else{
                    if(success){
                        success(operation.responseObject,responseObject);
                    }
                }
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                if(failure){
                    failure(operation.responseObject,error);
                }
            }];

        }
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 志愿者团体查询
-(void)requestGroupSearchWithGroupCode:(NSString *)groupCode
                           orgCode:(NSString *)orgCode
                           success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                           failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        if(groupCode.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"groupCode":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"groupCode":groupCode}];
        }
        
        if(orgCode.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"orgCode":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"orgCode":orgCode}];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/group/search?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestGroupSearchWithGroupCode:groupCode orgCode:orgCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 查询客户平台下面的团组织信息
-(void)requestGroupSearchOrgWithOrgCode:(NSString *)orgCode
                     isChildLevelFlag:(BOOL)isChildLevelFlag
                              success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                              failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        if(orgCode.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"orgCode":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"orgCode":orgCode}];
        }
        if(isChildLevelFlag==YES){
            [parameters setValuesForKeysWithDictionary:@{@"childLevelFlag":@"Y"}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"childLevelFlag":@"N"}];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/group/searchorg?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestGroupSearchOrgWithOrgCode:orgCode isChildLevelFlag:isChildLevelFlag success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
    
    
    
}

#pragma mark - 机构信息核实
-(void)requestGroupCheckAdmCodeWithAdmCode:(NSString *)admCode
                                 success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                 failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(admCode.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"admCode":admCode}];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/group/checkadmcode?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestGroupCheckAdmCodeWithAdmCode:admCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
    
    
}

#pragma mark - 志愿者注册
-(void)requestVolunteerRegisterWithGroupCode:(NSString *)groupCode
                            loginMobile:(NSString *)loginMobile
                            loginPasswd:(NSString *)loginPasswdAfterMD5
                               userType:(NSString *)userType
                               userName:(NSString *)userName
                                      gender:(NSString *)gender
                                    birthday:(NSString *)birthday
                        certificateType:(NSString *)certificateType
                          certificateNo:(NSString *)certificateNo
                             birthPlace:(NSString *)birthPlace
                               regPlace:(NSString *)regPlace
                            nationality:(NSString *)nationality
                               eduLevel:(NSString *)eduLevel
                        politicalStatus:(NSString *)politicalStatus
                               cylcUnit:(NSString *)cylcUnit
                               clycPost:(NSString *)clycPost
                           joinClycDate:(NSString *)joinClycDate
                              partyUnit:(NSString *)partyUnit
                           joinPartyDate:(NSString *)joinPartyDate
                              partyPost:(NSString *)partyPost
                       joinVolunteerDate:(NSString *)joinVolunteerDate
                         volunteerIssuse:(NSString *)volunteerIssuse
                   volunteerServiceHours:(NSString *)volunteerServiceHours
                          volunteerLevel:(NSString *)volunteerLevel
                             volunteerNo:(NSString *)volunteerNo
                          volunteerFlag:(NSString *)volunteerFlag
                      severiceTerritory:(NSString *)severiceTerritory
                        serviceLocation:(NSString *)serviceLocation
                           guardianName:(NSString *)guardianName
                         guardianMobile:(NSString *)guardianMobile
                                success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(groupCode.length==0||loginMobile.length==0||loginPasswdAfterMD5.length==0||userType.length==0||userName.length==0||certificateType.length==0||certificateNo.length==0||eduLevel.length==0||politicalStatus.length==0||volunteerFlag.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"groupCode":groupCode,@"loginMobile":loginMobile,@"loginPasswd":loginPasswdAfterMD5,@"userType":userType,@"userName":userName,@"certificateType":certificateType,@"certificateNo":certificateNo,@"eduLevel":eduLevel,@"politicalStatus":politicalStatus,@"guardianName":guardianName,@"guardianMobile":guardianMobile,@"volunteerFlag":volunteerFlag}];
        if(gender.length==0){
            [parameters setObject:[NSNull null] forKey:@"gender"];
        }else{
            [parameters setObject:gender forKey:@"gender"];
        }
        if(birthday.length==0){
            [parameters setObject:[NSNull null] forKey:@"birthday"];
        }else{
            [parameters setObject:birthday forKey:@"birthday"];
        }
        
        if(birthPlace.length==0){
            [parameters setObject:[NSNull null] forKey:@"birthPlace"];
        }else{
            [parameters setObject:birthPlace forKey:@"birthPlace"];
        }
        if( regPlace.length==0){
            [parameters setObject:[NSNull null] forKey:@"regPlace"];
        }else{
            [parameters setObject:regPlace forKey:@"regPlace"];
        }
        if(nationality.length==0){
            [parameters setObject:[NSNull null] forKey:@"nationality"];
        }else{
            [parameters setObject:nationality forKey:@"nationality"];
        }
        
        if(cylcUnit.length==0){
            [parameters setObject:[NSNull null] forKey:@"cylcUnit"];
        }else{
            [parameters setObject:cylcUnit forKey:@"cylcUnit"];
        }
        if(clycPost.length==0){
            [parameters setObject:[NSNull null] forKey:@"clycPost"];
        }else{
            [parameters setObject:clycPost forKey:@"clycPost"];
        }
        if(joinClycDate.length==0){
            [parameters setObject:[NSNull null] forKey:@"joinClycDate"];
        }else{
            [parameters setObject:joinClycDate forKey:@"joinClycDate"];
        }
        if(partyUnit.length==0){
            [parameters setObject:[NSNull null] forKey:@"partyUnit"];
        }else{
            [parameters setObject:partyUnit forKey:@"partyUnit"];
        }
        if(joinPartyDate.length==0){
            [parameters setObject:[NSNull null] forKey:@"joinPartyDate"];
        }else{
            [parameters setObject:joinPartyDate forKey:@"joinPartyDate"];
        }
        if(partyPost.length==0){
            [parameters setObject:[NSNull null] forKey:@"partyPost"];
        }else{
            [parameters setObject:partyPost forKey:@"partyPost"];
        }
        if(joinVolunteerDate.length==0){
            [parameters setObject:[NSNull null] forKey:@"joinVolunteerDate"];
        }else{
            [parameters setObject:joinVolunteerDate forKey:@"joinVolunteerDate"];
        }
        if(volunteerIssuse.length==0){
            [parameters setObject:[NSNull null] forKey:@"volunteerIssuse"];
        }else{
            [parameters setObject:volunteerIssuse forKey:@"volunteerIssuse"];
        }
        if(volunteerServiceHours.length==0){
            [parameters setObject:[NSNull null] forKey:@"volunteerServiceHours"];
        }else{
            [parameters setObject:volunteerServiceHours forKey:@"volunteerServiceHours"];
        }
        if(volunteerLevel.length==0){
            [parameters setObject:[NSNull null] forKey:@"volunteerLevel"];
        }else{
            [parameters setObject:volunteerLevel forKey:@"volunteerLevel"];
        }
        if(volunteerNo.length==0){
            [parameters setObject:[NSNull null] forKey:@"volunteerNo"];
        }else{
            [parameters setObject:volunteerNo forKey:@"volunteerNo"];
        }
        if(severiceTerritory.length==0){
            [parameters setObject:[NSNull null] forKey:@"severiceTerritory"];
        }else{
            [parameters setObject:severiceTerritory forKey:@"severiceTerritory"];
        }
        if(serviceLocation.length==0){
            [parameters setObject:[NSNull null] forKey:@"serviceLocation"];
        }else{
            [parameters setObject:serviceLocation forKey:@"serviceLocation"];
        }
        if(guardianName.length==0){
            [parameters setObject:[NSNull null] forKey:@"guardianName"];
        }else{
            [parameters setObject:guardianName forKey:@"guardianName"];
        }
        if(guardianMobile.length==0){
            [parameters setObject:[NSNull null] forKey:@"guardianMobile"];
        }else{
            [parameters setObject:guardianMobile forKey:@"guardianMobile"];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/reg?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerRegisterWithGroupCode:groupCode loginMobile:loginMobile loginPasswd:loginPasswdAfterMD5 userType:userType userName:userName gender:gender birthday:birthday certificateType:certificateType certificateNo:certificateNo birthPlace:birthPlace regPlace:regPlace nationality:nationality eduLevel:eduLevel politicalStatus:politicalStatus cylcUnit:cylcUnit clycPost:clycPost joinClycDate:joinClycDate partyUnit:partyUnit joinPartyDate:joinPartyDate partyPost:partyPost joinVolunteerDate:joinVolunteerDate volunteerIssuse:volunteerIssuse volunteerServiceHours:volunteerServiceHours volunteerLevel:volunteerLevel volunteerNo:volunteerNo volunteerFlag:volunteerFlag severiceTerritory:severiceTerritory serviceLocation:serviceLocation guardianName:guardianName guardianMobile:guardianMobile success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];

}

#pragma mark- 志愿者密码修改
-(void)requestVolunteerUpdatePwdWithVolunteerCode:(NSString *)volunteerCode
                                    oldPassword:(NSString *)oldPasswordAfterMD5
                                    newPassword:(NSString *)newPasswordAfterMD5
                                        success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                        failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(volunteerCode.length==0||newPasswordAfterMD5.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"volunteerCode":volunteerCode,@"newPassword":newPasswordAfterMD5,@"oldPassword":oldPasswordAfterMD5}];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/resetVolunteerPwd?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerUpdatePwdWithVolunteerCode:volunteerCode oldPassword:oldPasswordAfterMD5 newPassword:newPasswordAfterMD5 success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];

    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 志愿者查询（通讯录）
-(void)requestVolunteerFindVolunteerWithGroupCode:(NSString *)groupCode
                                   volunteerCode:(NSString *)volunteerCode
                                        success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                        failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        if(groupCode.length==0){
            [parameters setObject:[NSNull null] forKey:@"groupCode"];
        }else{
            [parameters setObject:groupCode forKey:@"groupCode"];
        }
        if(volunteerCode.length==0){
            [parameters setObject:[NSNull null] forKey:@"volunteerCode"];
        }else{
            [parameters setObject:volunteerCode forKey:@"volunteerCode"];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/findVolunteer?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerFindVolunteerWithGroupCode:groupCode volunteerCode:volunteerCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];

}

#pragma mark - 个人信息核实
-(void)requestVolunteerCheckinfoWithCertificateType:(NSString *)certificateType
                                      certificateNo:(NSString *)certificateNo
                                   name:(NSString *)name
                                 mobile:(NSString *)mobile
                                success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(certificateType.length==0||certificateNo.length==0||name.length==0||mobile.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"certificateType":certificateType,@"certificateNo":certificateNo,@"name":name,@"mobile":mobile}];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/checkinfo?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerCheckinfoWithCertificateType:certificateType certificateNo:certificateNo name:name mobile:mobile success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}
#pragma mark - 活动发布
-(void)requestActivityPostWithActivityName:(NSString *)activityName
                    activitySummary:(NSString *)activitySummary
               activityPostImgSmall:(NSString *)activityPostImgSmall
                   activityLocation:(NSString *)activityLocation
                activityStartPeriod:(NSString *)activityStartPeriod
                  activityEndPeriod:(NSString *)activityEndPeriod
                  activityDetailUrl:(NSString *)activityDetailUrl
             activityRegStartPeriod:(NSString *)activityRegStartPeriod
               activityRegEndPeriod:(NSString *)activityRegEndPeriod
                    activityCatalog:(NSString *)activityCatalog
                          groupCode:(NSString *)groupCode
                            success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                            failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(activityName.length==0||activityLocation.length==0||activityStartPeriod.length==0||activityEndPeriod.length==0||activityDetailUrl.length==0||activityRegStartPeriod.length==0||activityRegEndPeriod.length==0||groupCode.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        
        [parameters setValuesForKeysWithDictionary:@{@"activityName":activityName,@"activityLocation":activityLocation,@"activityStartPeriod":activityStartPeriod,@"activityEndPeriod":activityEndPeriod,@"activityDetailUrl":activityDetailUrl,@"activityRegStartPeriod":activityRegStartPeriod,@"activityRegEndPeriod":activityRegEndPeriod,@"groupCode":groupCode}];
        
        if(activitySummary.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activitySummary":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activitySummary":activitySummary}];
        }
        
        if(activityPostImgSmall.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activityPostImgSmall":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activityPostImgSmall":activityPostImgSmall}];
        }
        
        if(activityCatalog.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activityCatalog":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activityCatalog":activityCatalog}];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/post?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivityPostWithActivityName:activityName activitySummary:activitySummary activityPostImgSmall:activityPostImgSmall activityLocation:activityLocation activityStartPeriod:activityStartPeriod activityEndPeriod:activityEndPeriod activityDetailUrl:activityDetailUrl activityRegStartPeriod:activityRegStartPeriod activityRegEndPeriod:activityRegEndPeriod activityCatalog:activityCatalog groupCode:groupCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];

    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
    
}

#pragma mark - 活动信息更新
-(void)requestActivityUpdateWithActivityCode:(NSString *)activityCode
                         activityName:(NSString *)activityName
                      activitySummary:(NSString *)activitySummary
                 activityPostImgSmall:(NSString *)activityPostImgSmall
                     activityLocation:(NSString *)activityLocation
                  activityStartPeriod:(NSString *)activityStartPeriod
                    activityEndPeriod:(NSString *)activityEndPeriod
                    activityDetailUrl:(NSString *)activityDetailUrl
               activityRegStartPeriod:(NSString *)activityRegStartPeriod
                 activityRegEndPeriod:(NSString *)activityRegEndPeriod
                      activityCatalog:(NSString *)activityCatalog
                              success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                              failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(activityCode.length==0||activityName.length==0||activityLocation.length==0||activityStartPeriod.length==0||activityEndPeriod.length==0||activityDetailUrl.length==0||activityRegStartPeriod.length==0||activityRegEndPeriod.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        
        [parameters setValuesForKeysWithDictionary:@{@"activityCode":activityCode,@"activityName":activityName,@"activityLocation":activityLocation,@"activityStartPeriod":activityStartPeriod,@"activityEndPeriod":activityEndPeriod,@"activityDetailUrl":activityDetailUrl,@"activityRegStartPeriod":activityRegStartPeriod,@"activityRegEndPeriod":activityRegEndPeriod}];
        
        if(activitySummary.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activitySummary":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activitySummary":activitySummary}];
        }
        
        if(activityPostImgSmall.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activityPostImgSmall":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activityPostImgSmall":activityPostImgSmall}];
        }
        
        if(activityCatalog.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activityCatalog":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activityCatalog":activityCatalog}];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/update?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivityUpdateWithActivityCode:activityCode activityName:activityName activitySummary:activitySummary activityPostImgSmall:activityPostImgSmall activityLocation:activityLocation activityStartPeriod:activityStartPeriod activityEndPeriod:activityEndPeriod activityDetailUrl:activityDetailUrl activityRegStartPeriod:activityRegStartPeriod activityRegEndPeriod:activityRegEndPeriod activityCatalog:activityCatalog success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];

    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
    

}

#pragma mark - 活动查询
-(void)requestActivitySearchWithActivityName:(NSString *)activityName
                     activityLocation:(NSString *)activityLocation
                            groupCode:(NSString *)groupCode
                              success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                              failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(activityName.length==0&&activityLocation.length==0&&groupCode.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"3个条件都为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        if(activityName.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activityName":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activityName":activityName}];
        }
        
        if(activityLocation.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"activityLocation":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"activityLocation":activityLocation}];
        }
        
        if(groupCode.length==0){
            [parameters setValuesForKeysWithDictionary:@{@"groupCode":[NSNull null]}];
        }else{
            [parameters setValuesForKeysWithDictionary:@{@"groupCode":groupCode}];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/search?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivitySearchWithActivityName:activityName activityLocation:activityLocation groupCode:groupCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];

    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 志愿者登陆
-(void)requestAuthVolunteerWithVolunteerMobile:(NSString *)volunteerMobile
                            volunteerPwd:(NSString *)volunteerPwdAfterMD5
                                     success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                     failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(volunteerMobile.length==0||volunteerPwdAfterMD5.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"volunteerMobile":volunteerMobile,@"volunteerPwd":volunteerPwdAfterMD5,@"loginType":@"1"}];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/auth/volunteer?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestAuthVolunteerWithVolunteerMobile:volunteerMobile volunteerPwd:volunteerPwdAfterMD5 success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];

    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 活动报名
-(void)requestActivityRegisterWithActivityCode:(NSString *)activityCode
                                 volunteerCode:(NSString *)volunteerCode
                                   regStatus:(NSString *)regStatus
                                       regTime:(NSString *)regTime
                                     success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                     failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(activityCode.length==0||volunteerCode.length==0||regStatus.length==0||regTime.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"activityCode":activityCode,@"volunteerCode":volunteerCode,@"regStatus":regStatus,@"regTime":regTime}];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/reg?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivityRegisterWithActivityCode:activityCode volunteerCode:volunteerCode regStatus:regStatus regTime:regTime success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
        
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 活动签到
-(void)requestActivitySignWithActivityCode:(NSString *)activityCode
                                  volunteerCode:(NSString *)volunteerCode
                                     signType:(NSString *)signType
                                       signTime:(NSString *)signTime
                             signLongitude:(NSString *)signLongitude
                            signDimensions:(NSString *)signDimensions
                                       success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                       failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(activityCode.length==0||volunteerCode.length==0||signType.length==0||signTime.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"activityCode":activityCode,@"volunteerCode":volunteerCode,@"signType":signType,@"signTime":signTime}];
        if(signLongitude.length==0){
            [parameters setObject:[NSNull null] forKey:@"signLongitude"];
        }else{
            [parameters setObject:signLongitude forKey:@"signLongitude"];
        }
        if(signDimensions.length==0){
            [parameters setObject:[NSNull null] forKey:@"signDimensions"];
        }else{
            [parameters setObject:signDimensions forKey:@"signDimensions"];
        }

        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/sign?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivitySignWithActivityCode:activityCode volunteerCode:volunteerCode signType:signType signTime:signTime signLongitude:signLongitude signDimensions:signDimensions success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
        
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];

}

#pragma mark - 用户保单
-(void)requestVolunteerGetVolunteerInsuranceWithVolunteerCode:(NSString *)volunteerCode
                                                   success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                                   failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(volunteerCode.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"volunteerCode":volunteerCode}];
        
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/getVolunteerInsurance?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerGetVolunteerInsuranceWithVolunteerCode:volunteerCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
        
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];

}

#pragma mark - 补登
-(void)requestActivityRecord4UnregWithActiveName:(NSString *)activeName
                                 activeStartTime:(NSString *)activeStartTime
                                   activeEndTime:(NSString *)activeEndTime
                                        location:(NSString *)location
                                       groupCode:(NSString *)groupCode
                                    volunteerCode:(NSString *)volunteerCode
                                      activityCode:(NSString *)activityCode
                                         success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                         failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(activeName.length==0||activeStartTime.length==0||activeEndTime.length==0||groupCode.length==0||volunteerCode.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"activeName":activeName,@"activeStartTime":activeStartTime,@"activeEndTime":activeEndTime,@"groupCode":groupCode,@"volunteerCode":volunteerCode}];
        if(location.length==0){
            [parameters setObject:[NSNull null] forKey:@"location"];
        }else{
            [parameters setObject:location forKey:@"location"];
        }
        
        if(activityCode.length==0){
            [parameters setObject:[NSNull null] forKey:@"activityCode"];
        }else{
            [parameters setObject:activityCode forKey:@"activityCode"];
        }
        
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/record4Unreg?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivityRecord4UnregWithActiveName:activeName activeStartTime:activeStartTime activeEndTime:activeEndTime location:location groupCode:groupCode volunteerCode:volunteerCode activityCode:activityCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
        
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 广告
-(void)requestAdvertEnquiryWithVolunteerCode:(NSString *)volunteerCode
                                     module:(NSString *)module
                                   location:(NSString *)location
                                    success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                    failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        if(volunteerCode.length==0){
            [parameters setObject:[NSNull null] forKey:@"volunteerCode"];
        }else{
            [parameters setObject:volunteerCode forKey:@"volunteerCode"];
        }
        
        if(module.length==0){
            [parameters setObject:[NSNull null] forKey:@"module"];
        }else{
            [parameters setObject:module forKey:@"module"];
        }
        
        if(location.length==0){
            [parameters setObject:[NSNull null] forKey:@"location"];
        }else{
            [parameters setObject:location forKey:@"location"];
        }
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/advert/enquiry?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestAdvertEnquiryWithVolunteerCode:volunteerCode module:module location:location success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 扫描志愿者二维码
-(void)requestQrcodeVolunteerInfoWithVolunteerCode:(NSString *)volunteerCode
                                         success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                         failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setObject:volunteerCode forKey:@"volunteerCode"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/qrcode/volunteerInfo?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestQrcodeVolunteerInfoWithVolunteerCode:volunteerCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 扫描组织二维码
-(void)requestQrcodeGroupInfoWithGroupCode:(NSString *)groupCode
                                         success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                         failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setObject:groupCode forKey:@"groupCode"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/qrcode/groupInfo?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestQrcodeGroupInfoWithGroupCode:groupCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 扫描活动二维码
-(void)requestQrcodeActivityInfoWithActivityCode:(NSString *)activityCode
                                   success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                   failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setObject:activityCode forKey:@"activityCode"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/qrcode/activityInfo?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestQrcodeActivityInfoWithActivityCode:activityCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 全部信息
-(void)requestVolunteerNoticeAllNewsWithSuccess:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                        failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
//        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
//        [parameters setObject:@[@"1",@"100"] forKey:@"requestParam"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/VolunteerNotice/allNews?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerNoticeAllNewsWithSuccess:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 快讯播报
-(void)requestVolunteerNewsWithSuccess:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                        failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
//        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
//        [parameters setObject:@[@"1",@"100"] forKey:@"requestParam"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/VolunteerNotice/news?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerNewsWithSuccess:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 系统通知
-(void)requestVolunteerSystemNoticeWithSuccess:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                               failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        //        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        //        [parameters setObject:@[@"1",@"100"] forKey:@"requestParam"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/VolunteerNotice/systemNotice?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerSystemNoticeWithSuccess:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 我的信息
-(void)requestVolunteerGetVNoticesByGroupCodeWithGroupCode:(NSString *)groupCode
                                                   success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                                   failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setObject:groupCode forKey:@"groupCode"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/getVNoticesByGroupCode?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerGetVNoticesByGroupCodeWithGroupCode:groupCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 补登列表
-(void)requestActivityRecord4UnregListWithVolunteerCode:(NSString *)volunteerCode
                                               success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                               failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setObject:volunteerCode forKey:@"volunteerCode"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/activity/record4UnregList?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestActivityRecord4UnregListWithVolunteerCode:volunteerCode success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 忘记密码
-(void)requestVolunteerForgetVolunteerPwdWithLoginMobile:(NSString *)loginMobile
                                               last6IdNo:(NSString *)last6IdNo
                                                 success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                                 failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(loginMobile.length==0||last6IdNo.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setObject:loginMobile forKey:@"loginMobile"];
        [parameters setObject:last6IdNo forKey:@"last6IdNo"];
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/volunteer/forgetVolunteerPwd?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerForgetVolunteerPwdWithLoginMobile:loginMobile last6IdNo:last6IdNo success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];
}

#pragma mark - 检查版本
-(void)requestVersioniOSWithSuccess:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                            failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    if(self.clientId.length==0){
        NSError *error=[[NSError alloc]initWithDomain:@"clientId信息有误" code:0 userInfo:nil];
        if(failure){
            failure(nil,error);
        }
        return;
    }
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/version/ios?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVersioniOSWithSuccess:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }

    }];
}

#pragma mark - 城市Json
-(void)requestRegionRegionWithSuccess:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                              failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/region/region?client=%@&token=%@",apiUrl,self.clientId,token];
        
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestRegionRegionWithSuccess:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
        
    }];
}


#pragma mark - RSA加密
- (NSString *)encryptStrWithPublicKey:(NSString *)str{
    if(self.rsa){
        return [self.rsa encryptStrWithPublicKey:str];
    }else{
        return nil;
    }
}

#pragma mark - RSA解密
- (NSString *)decryptStrWithPublicKey:(NSString *)str{
    if(self.rsa){
        return [self.rsa decryptStrWithPublicKey:str];
    }else{
        return nil;
    }
}

#pragma mark - 是否清除本地token，以便下次直接获取token
-(void)deleteTokenInfoWithResponseObject:(id)responseObject{
    if(![responseObject isKindOfClass:[NSDictionary class]]||[responseObject[@"ret"] intValue]==1003){
        self.token=nil;
        self.tokenTimeOut=nil;
    }
}

#pragma mark - 是否需要刷新
-(BOOL)isRefreshWithResponseObject:(id)responseObject{
    if([responseObject isKindOfClass:[NSDictionary class]]&&responseObject[@"ret"]!=nil){
        if([responseObject[@"ret"] intValue]==1003){
            self.token=nil;
            self.tokenTimeOut=nil;
            return YES;
        }
    }
    return NO;
}

#pragma mark - 理赔信息录入
-(void)requestVolunteerClaimInsuranceWithInsuranceId:(NSString *)insuranceId
                                        recordId:(NSString *)recordId
                                          dangerDate:(NSString *)dangerDate
                                     bankAccountName:(NSString *)bankAccountName
                                         bankAccount:(NSString *)bankAccount
                                     bankAccountCity:(NSString *)bankAccountCity
                                            bankName:(NSString *)bankName
                                      bankBranchName:(NSString *)bankBranchName
                                   bankSubBranchName:(NSString *)bankSubBranchName
                                      contactAddress:(NSString *)contactAddress
                                           applyCost:(NSString *)applyCost
                                      medicalPayList:(NSArray *)medicalPayList
                                  identificationList:(NSArray *)identificationList
                                   medicalRecordList:(NSArray *)medicalRecordList
                                      inHospitalList:(NSArray *)inHospitalList
                                  medicalExpenseList:(NSArray *)medicalExpenseList
                                     checkReportList:(NSArray *)checkReportList
                                        accidentList:(NSArray *)accidentList
                                             success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
              failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(insuranceId.length==0||recordId.length==0||dangerDate.length==0||bankAccount.length==0||bankAccountCity.length==0||bankName.length==0||contactAddress.length==0||applyCost.length==0||medicalPayList.count==0||identificationList.count==0||medicalRecordList.count==0||bankAccountName.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"insuranceId":insuranceId,@"recordId":recordId,@"dangerDate":dangerDate,@"bankAccountName":bankAccountName,@"bankAccount":bankAccount,@"bankAccountCity":bankAccountCity,@"bankName":bankName,@"bankBranchName":bankBranchName,@"bankSubBranchName":bankSubBranchName,@"contactAddress":contactAddress,@"applyCost":applyCost,@"medicalPayList":medicalPayList,@"identificationList":identificationList,@"medicalRecordList":medicalRecordList}];
        if(bankBranchName.length==0){
            [parameters setValue:[NSNull null] forKey:@"bankBranchName"];
        }else{
            [parameters setValue:bankBranchName forKey:@"bankBranchName"];
        }
        if(bankSubBranchName.length==0){
            [parameters setValue:[NSNull null] forKey:@"bankSubBranchName"];
        }else{
            [parameters setValue:bankSubBranchName forKey:@"bankSubBranchName"];
        }
        if(inHospitalList.count==0){
            [parameters setValue:[NSNull null] forKey:@"inHospitalList"];
        }else{
            [parameters setValue:inHospitalList forKey:@"inHospitalList"];
        }
        if(medicalExpenseList.count==0){
            [parameters setValue:[NSNull null] forKey:@"medicalExpenseList"];
        }else{
            [parameters setValue:medicalExpenseList forKey:@"medicalExpenseList"];
        }
        if(checkReportList.count==0){
            [parameters setValue:[NSNull null] forKey:@"checkReportList"];
        }else{
            [parameters setValue:checkReportList forKey:@"checkReportList"];
        }
        if(accidentList.count==0){
            [parameters setValue:[NSNull null] forKey:@"accidentList"];
        }else{
            [parameters setValue:accidentList forKey:@"accidentList"];
        }
        
        
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/insurance/claimInsurance?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestVolunteerClaimInsuranceWithInsuranceId:insuranceId recordId:recordId dangerDate:dangerDate bankAccountName:bankAccountName bankAccount:bankAccount bankAccountCity:bankAccountCity bankName:bankName bankBranchName:bankBranchName bankSubBranchName:bankSubBranchName contactAddress:contactAddress applyCost:applyCost medicalPayList:medicalPayList identificationList:identificationList medicalRecordList:medicalRecordList inHospitalList:inHospitalList medicalExpenseList:medicalExpenseList checkReportList:checkReportList accidentList:accidentList success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
        
    }];

}

#pragma mark - 获取银行信息
-(void)requestInsuranceGetBankListWithSuccess:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                              failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/insurance/getBankList?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestInsuranceGetBankListWithSuccess:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
        
    }];
}

#pragma mark - 获取理赔结果
-(void)requestInsuranceSearchClaimResultWithVolunteerCode:(NSString *)volunteerCode
                                             recordId:(NSString *)recordId
                                                  Success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                                  failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(volunteerCode.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"volunteerCode":volunteerCode}];
        if(recordId.length==0){
            [parameters setObject:[NSNull null] forKey:@"recordId"];
        }else{
            [parameters setObject:recordId forKey:@"recordId"];
        }
        
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/insurance/searchClaimResult?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestInsuranceSearchClaimResultWithVolunteerCode:volunteerCode recordId:recordId Success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
        
    }];
}

#pragma mark - 更新理赔信息（补充资料）
-(void)requestInsuranceUpdateClaimWithClaimId:(NSString *)claimId
                                  insuranceId:(NSString *)insuranceId
                                         recordId:(NSString *)recordId
                                       dangerDate:(NSString *)dangerDate
                                  bankAccountName:(NSString *)bankAccountName
                                      bankAccount:(NSString *)bankAccount
                                  bankAccountCity:(NSString *)bankAccountCity
                                         bankName:(NSString *)bankName
                                   bankBranchName:(NSString *)bankBranchName
                                bankSubBranchName:(NSString *)bankSubBranchName
                                   contactAddress:(NSString *)contactAddress
                                        applyCost:(NSString *)applyCost
                                   medicalPayList:(NSArray *)medicalPayList
                               identificationList:(NSArray *)identificationList
                                medicalRecordList:(NSArray *)medicalRecordList
                                   inHospitalList:(NSArray *)inHospitalList
                               medicalExpenseList:(NSArray *)medicalExpenseList
                                  checkReportList:(NSArray *)checkReportList
                                     accidentList:(NSArray *)accidentList
                                          success:(void (^)(NSHTTPURLResponse *response, id responseObject))success
                                          failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure{
    [self requestTokenWithSuccess:^(int ret, NSString *token, NSString *expireTime) {
        if(claimId.length==0||insuranceId.length==0||recordId.length==0||dangerDate.length==0||bankAccount.length==0||bankAccountCity.length==0||bankName.length==0||contactAddress.length==0||applyCost.length==0||bankAccountName.length==0){
            NSError *error=[[NSError alloc]initWithDomain:@"必填信息不能为空" code:0 userInfo:nil];
            if(failure){
                failure(nil,error);
            }
            return;
        }
        NSMutableDictionary *parameters=[[NSMutableDictionary alloc]init];
        [parameters setValuesForKeysWithDictionary:@{@"claimId":claimId,@"insuranceId":insuranceId,@"recordId":recordId,@"dangerDate":dangerDate,@"bankAccountName":bankAccountName,@"bankAccount":bankAccount,@"bankAccountCity":bankAccountCity,@"bankName":bankName,@"bankBranchName":bankBranchName,@"bankSubBranchName":bankSubBranchName,@"contactAddress":contactAddress,@"applyCost":applyCost,@"medicalPayList":medicalPayList,@"identificationList":identificationList,@"medicalRecordList":medicalRecordList}];
        if(bankBranchName.length==0){
            [parameters setValue:[NSNull null] forKey:@"bankBranchName"];
        }else{
            [parameters setValue:bankBranchName forKey:@"bankBranchName"];
        }
        if(bankSubBranchName.length==0){
            [parameters setValue:[NSNull null] forKey:@"bankSubBranchName"];
        }else{
            [parameters setValue:bankSubBranchName forKey:@"bankSubBranchName"];
        }
        
        if(medicalPayList.count==0){
            [parameters setValue:[NSNull null] forKey:@"medicalPayList"];
        }else{
            [parameters setValue:medicalPayList forKey:@"medicalPayList"];
        }
        if(identificationList.count==0){
            [parameters setValue:[NSNull null] forKey:@"identificationList"];
        }else{
            [parameters setValue:identificationList forKey:@"identificationList"];
        }
        if(medicalRecordList.count==0){
            [parameters setValue:[NSNull null] forKey:@"medicalRecordList"];
        }else{
            [parameters setValue:medicalRecordList forKey:@"medicalRecordList"];
        }
        
        if(inHospitalList.count==0){
            [parameters setValue:[NSNull null] forKey:@"inHospitalList"];
        }else{
            [parameters setValue:inHospitalList forKey:@"inHospitalList"];
        }
        if(medicalExpenseList.count==0){
            [parameters setValue:[NSNull null] forKey:@"medicalExpenseList"];
        }else{
            [parameters setValue:medicalExpenseList forKey:@"medicalExpenseList"];
        }
        if(checkReportList.count==0){
            [parameters setValue:[NSNull null] forKey:@"checkReportList"];
        }else{
            [parameters setValue:checkReportList forKey:@"checkReportList"];
        }
        if(accidentList.count==0){
            [parameters setValue:[NSNull null] forKey:@"accidentList"];
        }else{
            [parameters setValue:accidentList forKey:@"accidentList"];
        }
        
        
        NSString *urlStr=[[NSString alloc]initWithFormat:@"%@/insurance/updateClaim?client=%@&token=%@",apiUrl,self.clientId,token];
        [self.manager POST:urlStr parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
            if([self isRefreshWithResponseObject:responseObject]){
                [self requestInsuranceUpdateClaimWithClaimId:claimId insuranceId:insuranceId recordId:recordId dangerDate:dangerDate bankAccountName:bankAccountName bankAccount:bankAccount bankAccountCity:bankAccountCity bankName:bankName bankBranchName:bankBranchName bankSubBranchName:bankSubBranchName contactAddress:contactAddress applyCost:applyCost medicalPayList:medicalPayList identificationList:identificationList medicalRecordList:medicalRecordList inHospitalList:inHospitalList medicalExpenseList:medicalExpenseList checkReportList:checkReportList accidentList:accidentList success:success failure:failure];
            }else{
                if(success){
                    success(operation.responseObject,responseObject);
                }
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            if(failure){
                failure(operation.responseObject,error);
            }
        }];
    } failure:^(NSHTTPURLResponse *response, NSError *error) {
        if(failure){
            failure(response,error);
        }
    }];

}
@end
